package com.zcgame.base.utils

import com.zcgame.base.bean.LoadBean
import retrofit2.HttpException

/**
 *@author:huangLJ
 *@date:2021/4/27 14:30
 * 网络请求报错处理
 */

object NetWorkUtils{
    fun catchError(e:Exception):String?{
        when (e) {
            is HttpException -> {
                when(e.code()){
                    400 -> printError("给出错误的提示")
                    401 -> printError("被封号了")
                    403 -> printError("资源找不到")
                    404 -> printError("资源找不到，要跳去火星")
                    421 -> printError("未注册，要跳注册")
                    else ->{
                        if (e.code().toString().startsWith("5")){
                            printError("服务器错误")
                        }else{
                            e.printStackTrace()
                        }
                    }
                }
            }
            is KotlinNullPointerException -> {
                //TODO:数据为空处理
                return LoadBean.EMPTY
            }
            else -> {
                e.printStackTrace()
            }
        }
        return LoadBean.FAILED
    }
}